package com.jiesen.base.modules.login.jsPermission.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jiesen.base.baseDao.BaseServiceImpl;
import com.jiesen.base.modules.login.jsPermission.mapper.PermissionDao;
import com.jiesen.base.modules.login.jsPermission.model.Permission;
import com.jiesen.base.modules.login.jsPermission.service.PermissionService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionServiceImpl extends BaseServiceImpl<PermissionDao, Permission> implements PermissionService {

    //查询所有的权限
    @Override
    public List<Permission> findAll() {
        return baseMapper.selectList(null);
    }

    //查询所有权限信息（树状）
    @Override
    public List<Permission> findAll1() {
        List<Permission> permissions = findPermissionByParentId(0);
        //查询二级菜单
        for (Permission permission : permissions) {
            List<Permission> permissions1 = findPermissionByParentId(permission.getId());
            permission.setChild(permissions1);
        }
        //查询页面按钮权限
        return permissions;
    }

    @Override
    public List<Permission> findPermissionByParentId(Integer id) {
        QueryWrapper<Permission> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id",id);
        List<Permission> permissions = baseMapper.selectList(queryWrapper);
        return permissions;
    }
}
